//
//  TSRandomTextTool.swift
//  Pods
//
//  Created by 100Years on 2025/5/15.
//

public class TSRandomTextTool {
    private var texts: [String]
    private var lastIndex: Int?

    public init(texts: [String]) {
        self.texts = texts
    }
    
    public func getRandomText() -> String? {
        guard !texts.isEmpty else { return nil }
        
        var randomIndex: Int
        repeat {
            randomIndex = Int.random(in: 0..<texts.count)
        } while randomIndex == lastIndex
        
        lastIndex = randomIndex
        return texts[randomIndex]
    }
}
